			<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'west',split: true" style="width:20%">
		    	<div style="padding: 5px;">
					<ul id="zTreeDeptContent" class="ztree"></ul>
				</div>
		    </div>
		    
		    <div data-options="region:'center',border: false">
		    	<div style="padding: 5px;">
					<ul id="rightTree" class="ztree"></ul>
				</div>
			</div>
		</div>
			
			<!-- 
			<div class=" layout-panel   easyui-fluid" style="width:30%;height:98%">
		    	<div data-options="region:'west',split: true" style="width:80%;height:95%" class="panel-body panel-body-noheader layout-body ">
		    		<div style="padding: 5px;">
					<ul id="zTreeDeptContent" class="ztree"></ul>
					</div> 
				</div>
		    </div>
	    
	    <div class=" layout-panel " style=" left:350px;">
	    
		    <div data-options="region:'center',border: false"  class="panel-body panel-body-noheader panel-body-noborder layout-body"style="width: 635px; height: 652px;" >
		    	<div style="padding:5px;">
					<ul id="rightTree" class="ztree"></ul>
				</div>
			</div>
		</div> -->
		
		<script type="text/javascript">
			 var rightTreeSetting = {
					async: {
							enable : true,
							url : '${cxt! }/operator/treeData',
							autoParam : ["id=ids"],//, "level=lv"
							//otherParam : {"otherParam" : "zTreeAsyncTest"},
							type : "post"
						},
				view: {
					fontCss: getFont,
					expandSpeed: "",
					selectedMulti: false
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				check: {
					enable: true,
					autoCheckTrigger: true,
					chkStyle: "checkbox",
					chkboxType: { "Y": "ps", "N": "ps" },
					nocheckInherit: true
					
				},
				callback: 
				{
					beforeAsync: beforeAsync1, //用于捕获异步加载之前的事件回调函数,zTree 根据返回值确定是否允许进行异步加载
					onAsyncSuccess: onAsyncSuccess1, //用于捕获异步加载出现异常错误的事件回调函数
					onAsyncError: onAsyncError1,//用于捕获异步加载正常结束的事件回调函数
					beforeCheck: zTreeBeforeCheck,
					onCheck: rightTreeClick
				}
			};
			var setting = {
					 async: {
						enable : true,
						url : '${cxt! }/agentRight/treeData',
						autoParam : ["id=ids"],//, "name=n", "level=lv"
						//otherParam : {"otherParam" : "zTreeAsyncTest"},
						type : "post"
					}, 
				view: {
					fontCss: getFont,
					expandSpeed: "",
					addHoverDom: addHoverDom,
					removeHoverDom: removeHoverDom,
					selectedMulti: false
				},
				edit: {
					enable: true,
					removeTitle: "删除岗位",
					renameTitle: "编辑岗位名称"
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					onClick: zTreeOnClick,
					beforeRemove: beforeRemove, //节点被删除之前的事件,并且根据返回值确定是否允许删除操作
					beforeRename: beforeRename, //用于捕获节点编辑名称结束

						beforeAsync: beforeAsync, //用于捕获异步加载之前的事件回调函数,zTree 根据返回值确定是否允许进行异步加载
						onAsyncSuccess: onAsyncSuccess, //用于捕获异步加载出现异常错误的事件回调函数
						onAsyncError: onAsyncError//用于捕获异步加载正常结束的事件回调函数

//					beforeDrag: beforeDrag, //用于捕获节点被拖拽之前的事件回调函数，并且根据返回值确定是否允许开启拖拽操作
//					beforeDrop: beforeDrop, //用于捕获节点拖拽操作结束之前的事件回调函数，并且根据返回值确定是否允许此拖拽操作
//					beforeDragOpen: beforeDragOpen, //用于捕获拖拽节点移动到折叠状态的父节点后，即将自动展开该父节点之前的事件回调函数，并且根据返回值确定是否允许自动展开操作
//					onDrag: onDrag, //用于捕获节点被拖拽的事件回调函数
//					onDrop: onDrop, //用于捕获节点拖拽操作结束的事件回调函数
//					onExpand: onExpand //用于捕获节点被展开的事件回调函数
				}
			};
// 			  var data = [ /**自定义的数据源，ztree支持json,数组，xml等格式的**/
// 				{ id: 0, pId: -1, name: "总部", icon: "${cxt! }/sb/icons/icon/house.png" },
// 				{ id: 1, pId: 0, name: "代理商", icon: "${cxt! }/sb/icons/icon/user_brown.png" },
// 				{ id: 11, pId: 1, name: "门店", icon: "${cxt! }/sb/icons/icon/user_gray.png" }
// 			];  
			
	
			//字体设置
			function getFont(treeId, node) {
				return node.font ? node.font : {};
			}
			
			function zTreeOnClick(event, treeId, treeNode){
				/* $.fn.zTree.init($("#rightTree"), rightTreeSetting);
				var rightTree = $.fn.zTree.getZTreeObj("rightTree");
				rightTree.expandAll(true);
				 */
				var url = "/operator/getOper";
				var data= { "levelId": treeNode.id};
				var reData = common_ajax.ajaxFunc(url, data);
				var  daJson=JSON.parse(reData).data; 
				var  stJson=JSON.parse(reData).status; 
				if(stJson=="success" && daJson!=null)
				{	
					 var rightTree = $.fn.zTree.getZTreeObj("rightTree");
					 var node = rightTree.getNodes();
					 var nodes = rightTree.transformToArray(node);
					 //rightTree.checkAllNodes(false);
					 $(daJson).each(function(n, item) {
						 for(var i=0;i<nodes.length;i++){
						      if(nodes[i].id==item.ids)
						     {
					    	  rightTree.checkNode(rightTree.getNodeByParam("id", nodes[i].id, null), true, true);
						     		//rightTree.checkNode(nodes[i], true, true);
// 						     		nodes[i].checked
						     }
						 }
					 });
				}
			}
			　　
			function  zTreeBeforeCheck(event, treeId, treeNode)
			{
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
				var  selectedNode=zTree.getSelectedNodes();
				if(selectedNode[0]==null)
				{
					alert("请先选择一个层级！！");
					return  false;
				}
				return true;
			}
			function  rightTreeClick(event, treeId, treeNode)
			{	
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
				var  selectedNode=zTree.getSelectedNodes();
				var levelId=selectedNode[0].id;
				
					if(treeNode.checked && !treeNode.getCheckStatus().half)
					{	
						var url = "/operator/add";
						var data = { "levelRight.levelIds" :levelId,"levelRight.rightIds":treeNode.id};
						var result = common_ajax.ajaxFunc(url, data);
						var  statu=JSON.parse(result).status; 
						if(statu!="success"){
	// 						box.value = result.data; // 返回岗位功能主键
							alert("添加岗位功能设置失败！");
						}
						
					}else
					{	
						var url = "/operator/del" ;
						var data = { "levelRight.levelIds" :levelId,"levelRight.rightIds":treeNode.id};
						var result = common_ajax.ajaxFunc(url, data);
						var  statu=JSON.parse(result).status; 
						if(statu != "success"){
							alert("删除岗位功能设置失败！");
						}
					}
			}
			////////////////////下面是处理增删改节点//////////////////

			//节点被删除之前的事件,并且根据返回值确定是否允许删除操作
			function beforeRemove(treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
				zTree.selectNode(treeNode);

				var result = false;
				if(confirm("确认删除<" + treeNode.name + ">部门吗？")) {
					var url = "/agentRight/delete";
					var data = { "ids": treeNode.id};

					var reData = common_ajax.ajaxFunc(url, data);
					if(reData != treeNode.id) {
						alert("删除<" + treeNode.name + ">部门失败！");
					} else {
						result = true;
					}
					result = true;
				}

				return result;
			}

			//用于捕获节点编辑名称
			function beforeRename(treeId, treeNode, newName, isCancel) {
				if(treeNode.name == newName) {
					return true;
				} else if(newName.length == 0) {
					alert("部门名称不能为空！");
					return false;
				} else {
					var url = "/agentRight/update";
					var data = { "ids": treeNode.id, "pIds":treeNode.id,"name": newName };

					var reData = common_ajax.ajaxFunc(url, data);
					if(reData !="") {
						return true;
					} else {
						alert("修改<" + treeNode.name + ">部门名称失败！");
						return false;
					}
				}
			}

			//添加功能按钮
			var newCount = 1;

			function addHoverDom(treeId, treeNode) {
				var sObj = $("#" + treeNode.tId + "_span");
				if(treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) {
					return;
				}
				
				//1.处理添加按钮
				var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='添加岗位' onfocus='this.blur();'></span>";
				sObj.after(addStr);
				var btn = $("#addBtn_" + treeNode.tId);
				if(btn) btn.bind("click", function() {
					
					var newId = (newCount++);
					var addName = "新增岗位" + newId; //部门初始化名称
					alert(treeNode.tId);
//					var orderIds = (treeNode.children == undefined ? 1 : (treeNode.children.length + 1));
					alert(addName);
					var url = "/agentRight/save";
					var data = {
						"pIds": treeNode.id,
						"name": addName,
						"images":"user_brown.png"
// 						"orderIds": orderIds,
// 						"csrfToken": "${csrfToken!}"
					};
					var reData = common_ajax.ajaxFunc(url, data);
					if(reData != "") {
						var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
						zTree.addNodes(treeNode, { id: reData, pId: treeNode.id, name: addName});
						/* var node = zTree.getNodeByParam("id", newId, null); //根据新的id找到新添加的节点  
           		 		zTree.selectNode(node); //让新添加的节点处于选中状态   */
					} else {
						alert("新增部门失败！");
					}

					return false;
				});

				//2.添加岗位
////				var operatorStr = "<span class='button edit' id='operatorBtn_" + treeNode.tId + "' title='设置部门负责人' onfocus='this.blur();'></span>";
//				var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='添加岗位' onfocus='this.blur();'></span>";
//				sObj.after(addStr);
//				var btn = $("#addBtn_" + treeNode.tId);
//				if(btn) btn.bind("click", function() {
//					$("#dlg").dialog("open");
//				});
				
				//3.设置权限
//				var operatorStr = "<span class='button edit' id='operatorBtn_" + treeNode.tId + "' title='设置权限' onfocus='this.blur();'></span>";
//				sObj.after(operatorStr);
//				var btn = $("#operatorBtn_" + treeNode.tId);
//				if(btn) btn.bind("click", function() {
//					$("#dlg").dialog("open");
//				});
			};

			function removeHoverDom(treeId, treeNode) {
				//1.处理添加按钮
				$("#addBtn_" + treeNode.tId).unbind().remove();
				//2.处理查看按钮
				$("#operatorBtn_" + treeNode.tId).unbind().remove();
			};

			////////////////////下面是处理展开//////////////////

			//用于捕获异步加载之前的事件回调函数,zTree 根据返回值确定是否允许进行异步加载
			function beforeAsync() {
				curAsyncCount++;
			}
			//用于捕获异步加载之前的事件回调函数,zTree 根据返回值确定是否允许进行异步加载
			function beforeAsync1() {
				
				curAsyncCount1++;
			}

			//用于捕获异步加载出现异常错误的事件回调函数
			function onAsyncSuccess(event, treeId, treeNode, msg) {
				curAsyncCount--;
				if(curStatus == "expand") {
					expandNodes(treeNode.children);
				} else if(curStatus == "async") {
					asyncNodes(treeNode.children);
				}

				if(curAsyncCount <= 0) {
					if(curStatus != "init" && curStatus != "") {
						//$("#demoMsg").text((curStatus == "expand") ? "全部展开完毕" : "后台异步加载完毕");
						asyncForAll = true;
					}
					curStatus = "";
				}
			}
			//用于捕获异步加载出现异常错误的事件回调函数
			function onAsyncSuccess1(event, treeId, treeNode, msg) {
				curAsyncCount1--;
				if(curStatus1 == "expand") {
					expandNodes1(treeNode.children);
				} else if(curStatus1 == "async") {
					asyncNodes1(treeNode.children);
				}

				if(curAsyncCount1 <= 0) {
					if(curStatus1 != "init" && curStatus1 != "") {
						//$("#demoMsg").text((curStatus == "expand") ? "全部展开完毕" : "后台异步加载完毕");
						asyncForAll1 = true;
					}
					curStatus1 = "";
				}
			}

			//用于捕获异步加载正常结束的事件回调函数
			function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
				curAsyncCount--;

				if(curAsyncCount <= 0) {
					curStatus = "";
					if(treeNode != null) asyncForAll = true;
				}
			}
			//用于捕获异步加载正常结束的事件回调函数
			function onAsyncError1(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
				curAsyncCount1--;

				if(curAsyncCount1 <= 0) {
					curStatus1 = "";
					if(treeNode != null) asyncForAll1 = true;
				}
			}
			var curStatus = "init",
				curStatus1 = "init",
				curAsyncCount = 0,
				curAsyncCount1 = 0,
				asyncForAll = false,
				asyncForAll1 = false,
				goAsync = false;
				goAsync1 = false;
			function expandAll() {
				if(!check()) {
					return;
				}
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
 				var rightTree = $.fn.zTree.getZTreeObj("rightTree");
				if(asyncForAll) {
					//$("#demoMsg").text("已经异步加载完毕，使用 expandAll 方法");
					zTree.expandAll(true);
				} else {
					expandNodes(zTree.getNodes());
 					expandNodes1(rightTree.getNodes());
					if(!goAsync && !goAsync1) {
						//$("#demoMsg").text("已经异步加载完毕，使用 expandAll 方法");
						curStatus = "";
					}
				}
			}
			
			function expandAll1() {
				if(!check1()) {
					return;
				}
 				var rightTree = $.fn.zTree.getZTreeObj("rightTree");
				if(asyncForAll1) {
					//$("#demoMsg").text("已经异步加载完毕，使用 expandAll 方法");
					rightTree.expandAll(true);
				} else {
					expandNodes1(rightTree.getNodes());
 					expandNodes1(rightTree.getNodes());
					if(!goAsync1 ) {
						//$("#demoMsg").text("已经异步加载完毕，使用 expandAll 方法");
						curStatus1 = "";
					}
				}
			}
			 function expandNodes(nodes) {
				if(!nodes) {
					return;
				}
				curStatus = "expand";
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
				for(var i = 0, l = nodes.length; i < l; i++) {
					zTree.expandNode(nodes[i], true, false, false);
					if(nodes[i].isParent && nodes[i].zAsync) {
						expandNodes(nodes[i].children);
					} else {
						goAsync = true;
					}
				}
			}
			
			 function expandNodes1(nodes) {
					if(!nodes) {
						return;
					}
					curStatus1 = "expand";
					var rightTree = $.fn.zTree.getZTreeObj("rightTree");
					for(var i = 0, l = nodes.length; i < l; i++) {
						rightTree.expandNode(nodes[i], true, false, false);
						if(nodes[i].isParent && nodes[i].zAsync) {
							expandNodes(nodes[i].children);
						} else {
							goAsync1 = true;
						}
					}
				}

			function asyncAll() {
				if(!check()) {
					return;
				}
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
				if(asyncForAll) {
					//$("#demoMsg").text("已经异步加载完毕，不再重新加载");
				} else {
					asyncNodes(zTree.getNodes());
					if(!goAsync) {
						//$("#demoMsg").text("已经异步加载完毕，不再重新加载");
						curStatus = "";
					}
				}
			}
			function asyncAll1() {
				if(!check1()) {
					return;
				}
				var rightTree = $.fn.zTree.getZTreeObj("rightTree");
				if(asyncForAll1) {
					//$("#demoMsg").text("已经异步加载完毕，不再重新加载");
				} else {
					asyncNodes1(rightTree.getNodes());
					if(!goAsync1) {
						//$("#demoMsg").text("已经异步加载完毕，不再重新加载");
						curStatus1 = "";
					}
				}
			}

			function asyncNodes(nodes) {
				if(!nodes) {
					return;
				}
				curStatus = "async";
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
				for(var i = 0, l = nodes.length; i < l; i++) {
					if(nodes[i].isParent && nodes[i].zAsync) {
						asyncNodes(nodes[i].children);
					} else {
						goAsync = true;
						zTree.reAsyncChildNodes(nodes[i], "refresh", true);
					}
				}
			}
			function asyncNodes1(nodes) {
				if(!nodes) {
					return;
				}
				curStatus1 = "async";
				var rightTree = $.fn.zTree.getZTreeObj("rightTree");
				for(var i = 0, l = nodes.length; i < l; i++) {
					if(nodes[i].isParent && nodes[i].zAsync) {
						asyncNodes1(nodes[i].children);
					} else {
						goAsync1 = true;
						rightTree.reAsyncChildNodes(nodes[i], "refresh", true);
					}
				}
			}
// 			function reset() {
// 				if(!check()) {
// 					return;
// 				}
// 				asyncForAll = false;
// 				goAsync = false;
// 				//$("#demoMsg").text("");
// 				$.fn.zTree.init($("#treeDemo"), setting);
// 			}

			function check() {
				if(curAsyncCount > 0) {
					//$("#demoMsg").text("正在进行异步加载，请等一会儿再点击...");
					return false;
				}
				return true;
			}

			function check1() {
				if(curAsyncCount1 > 0) {
					//$("#demoMsg").text("正在进行异步加载，请等一会儿再点击...");
					return false;
				}
				return true;
			}

			////////////////////下面是处理拖拽///////////////////

//			function dropPrev(treeId, nodes, targetNode) {
//				var pNode = targetNode.getParentNode();
//				if(pNode && pNode.dropInner === false) {
//					return false;
//				} else {
//					for(var i = 0, l = curDragNodes.length; i < l; i++) {
//						var curPNode = curDragNodes[i].getParentNode();
//						if(curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
//							return false;
//						}
//					}
//				}
//				return true;
//			}
//
//			function dropInner(treeId, nodes, targetNode) {
//				if(targetNode && targetNode.dropInner === false) {
//					return false;
//				} else {
//					for(var i = 0, l = curDragNodes.length; i < l; i++) {
//						if(!targetNode && curDragNodes[i].dropRoot === false) {
//							return false;
//						} else if(curDragNodes[i].parentTId && curDragNodes[i].getParentNode() !== targetNode && curDragNodes[i].getParentNode().childOuter === false) {
//							return false;
//						}
//					}
//				}
//				return true;
//			}
//
//			function dropNext(treeId, nodes, targetNode) {
//				var pNode = targetNode.getParentNode();
//				if(pNode && pNode.dropInner === false) {
//					return false;
//				} else {
//					for(var i = 0, l = curDragNodes.length; i < l; i++) {
//						var curPNode = curDragNodes[i].getParentNode();
//						if(curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
//							return false;
//						}
//					}
//				}
//				return true;
//			}

			//用于捕获节点被拖拽之前的事件回调函数，并且根据返回值确定是否允许开启拖拽操作
//			var log, className = "dark",
//				curDragNodes, autoExpandNode;
//
//			function beforeDrag(treeId, treeNodes) {
//				className = (className === "dark" ? "" : "dark");
//				for(var i = 0, l = treeNodes.length; i < l; i++) {
//					if(treeNodes[i].drag === false) {
//						curDragNodes = null;
//						return false;
//					} else if(treeNodes[i].parentTId && treeNodes[i].getParentNode().childDrag === false) {
//						curDragNodes = null;
//						return false;
//					}
//				}
//				curDragNodes = treeNodes;
//				return true;
//			}

			//用于捕获拖拽节点移动到折叠状态的父节点后，即将自动展开该父节点之前的事件回调函数，并且根据返回值确定是否允许自动展开操作
//			function beforeDragOpen(treeId, treeNode) {
//				autoExpandNode = treeNode;
//				return true;
//			}

			//用于捕获节点拖拽操作结束之前的事件回调函数，并且根据返回值确定是否允许此拖拽操作
//			function beforeDrop(treeId, treeNodes, targetNode, moveType, isCopy) {
//				className = (className === "dark" ? "" : "dark");
//				return true;
//			}

			//用于捕获节点被拖拽的事件回调函数
//			function onDrag(event, treeId, treeNodes) {
//				className = (className === "dark" ? "" : "dark");
//			}

			//用于捕获节点拖拽操作结束的事件回调函数
//			function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
//				className = (className === "dark" ? "" : "dark");
//				//alert(treeNodes.length + ":"+treeNodes[0].id + ", " + (targetNode ? (targetNode.id + ", " + targetNode.name) : "isRoot" ));
//				if(treeNodes.length > 0 && targetNode) {
//					var dragId = treeNodes[0].id; //被拖拽部门
//					var targetId = targetNode.id; //拖拽到的目标部门
//
//					var url = "/platform/dept/update";
//					var data = { "ids": dragId, "pIds": targetId, "csrfToken": "${csrfToken!}" };
//
//					var reData = common_ajax.ajaxFunc(url, data);
//					if(reData != dragId) {
//						common_modals.alert("移动部门失败！");
//					}
//				}
//			}

			//用于捕获节点被展开的事件回调函数
			function onExpand(event, treeId, treeNode) {
				if(treeNode === autoExpandNode) {
					className = (className === "dark" ? "" : "dark");
				}
			}

			function setTrigger() {
				var zTree = $.fn.zTree.getZTreeObj("zTreeDeptContent");
				zTree.setting.edit.drag.autoExpandTrigger = $("#callbackTrigger").attr("checked");
			}

			//////////////////初始化////////////////////

			$(document).ready(function() {
				$.fn.zTree.init($("#zTreeDeptContent"), setting);
				$.fn.zTree.init($("#rightTree"), rightTreeSetting);
//				$("#callbackTrigger").bind("change", {}, setTrigger); //拖拽节点时自动展开父节点是否触发

				//$("#expandAllBtn").bind("click", expandAll);	//全部展开
				//$("#asyncAllBtn").bind("click", asyncAll);	//背后展开
				//$("#resetBtn").bind("click", reset);	//重置
			});

			 setTimeout(function() {
				
					expandAll();
					expandAll1();
			}, 500); 
		</script>

